package airplane.com.example.controller;

import airplane.com.example.entry.Airplane;
import airplane.com.example.service.AirplaneService;
import airplane.com.example.utilities.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/airplane")
public class AirplaneController {
    @Autowired
    private AirplaneService airplaneService;

    @GetMapping("/findByPage")
    public Map<String,Object> findByPage(Integer currentPage, Integer pageSize) {
        currentPage = currentPage == null ? 0 : currentPage;
        pageSize = pageSize == null ? 14 : pageSize;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("user", airplaneService.findByPage(currentPage, pageSize));
        map.put("pageTotal", airplaneService.findTotal());
        return map;
    }

    @PostMapping("/addAirplane")
    public Result addAirplane(@RequestBody Airplane airplane) {
        return airplaneService.addAirplane(airplane);
    }

    @PostMapping("/updateAirplane")
    public Result updateAirplane(@RequestBody Airplane airplane) {
        return airplaneService.updateAirplane(airplane);
    }

    @PostMapping("/deleteAirplane")
    public Result deleteAirplane(@RequestParam String airplane) {
        return airplaneService.deleteAirplane(airplane);
    }
}
